package lyc.springcloud.admin.controller.systemManagerController;


import lombok.extern.slf4j.Slf4j;
import lyc.springcloud.admin.dto.systemManagerDto.UserManagerDto;
import lyc.springcloud.admin.service.def.systemManagerService.UserManagerService;
import lyc.springcloud.admin.utils.CommonResClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/systemManager/userManager")
@Slf4j
public class UserManagerController {
    @Autowired
    private UserManagerService userManagerService;

    /**
     * 查询所有启用的角色
     * */
    @GetMapping("selectAllEnableRoles")
    public CommonResClass selectAllEnableRoles(){
        try {
            List<Map> list =  userManagerService.selectAllEnableRoles();
            return CommonResClass.success(list);
        } catch (Exception e) {
            log.error("查询所有启用的角色", e);
            return CommonResClass.failure();
        }
    }

    /**
     * 用户管理---新增
    * */
    @PostMapping("insert")
    public CommonResClass userMng_insert(@RequestBody UserManagerDto params){
        try {
            userManagerService.userMng_insert(params);
            return CommonResClass.success();
        } catch (Exception e) {
            log.error("用户管理---新增", e);
            return CommonResClass.failure();
        }
    }

    /**
     * 用户管理---查询
    * */
    @PostMapping("select")
    public CommonResClass userMng_select(@RequestBody UserManagerDto params){
        try {
            Map<String, Object> map =  userManagerService.userMng_select(params);
            return CommonResClass.success(map);
        } catch (Exception e) {
            log.error("用户管理---查询", e);
            return CommonResClass.failure();
        }
    }

    /**
     * 用户管理---编辑
    * */
    @PostMapping("update")
    public CommonResClass userMng_update(@RequestBody UserManagerDto params){
        try {
            userManagerService.userMng_update(params);
            return CommonResClass.success();
        } catch (Exception e) {
            log.error("用户管理---编辑", e);
            return CommonResClass.failure();
        }
    }

    /**
     * 用户管理---删除
    * */
    @GetMapping("delete")
    public CommonResClass userMng_delete(@RequestParam("userIds") String params){
        try {
            userManagerService.userMng_delete(params);
            return CommonResClass.success();
        } catch (Exception e) {
            log.error("用户管理---删除", e);
            return CommonResClass.failure();
        }
    }
}
